package com.cloud.basic.DefineClassLoader;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TestMain {

    public static void main(String[] args) {
        // 加载自定义类加载器路径
        DefineClassLoader dcl = new DefineClassLoader("D:\\lib");

        try {
            // 包+类名
            Class c = dcl.loadClass("com.cloud.basic.DefineClassLoader.Test");

            System.out.println(c);
            if (c != null) {
                // 获取一个实例
                Object o = c.newInstance();

                // 通过反射获取该类的一个方法
                Method method = c.getDeclaredMethod("say", null);

                // 调用
                method.invoke(o,null);
            }
        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException |
                NoSuchMethodException | InvocationTargetException e) {
            e.printStackTrace();
        }

    }

}

